<?php

require_once '../include/common.inc.php';

if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}
//ɲ룬£ɾȲˢ
if($continue!="")header("localtion: m_other.php"); 

$menu_index = 3;
$page_title = 'TABLA';
$guide_message = 'Media | Customer Other';
$out_ary = array();
$ppp = 20;
$page_show = '';

//echo "<pre>";print_r($_POST);
getMyParam('action');



$search_flag = false;
$page_url = 'm_other.php?';
$sql_where = '';


if ($action != "") {
	
    if ($action == 'edit') {
        getMyParam('mkey'); 
		getMyParam('mkey_danish'); 
		getMyParam('mvalue');  
		getMyParam('mvalue_danish'); 
        getMyParam('cid');

        $sql = "update `med_other` set mkey='$mkey',mkey_danish='$mkey_danish',
				mvalue='$mvalue',mvalue_danish='$mvalue_danish' where id=$cid";
        $db->query($sql);
	    $msg="This other has been updated.";
		$href="m_other.php";
		include_once('menu_list.php');
		require_once PrintEot('a_header');
		require_once PrintEot('a_msg');
		require_once PrintEot('a_footer');   
		exit;

    }
	
	if ($action == "search") {
	getMyParam('search_key');
    $sql_where .= " where  `mkey` LIKE '%$search_key%' or `mvalue` LIKE '%$search_key%'";
    $page_url = 'm_other.php?action=search&search_key=' . $search_key;
	}
	
}else $sql_where="";



$sql = "SELECT * FROM `med_other` $sql_where";

$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);


// *** page code start ***
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
    $start_limit = 0;
    $page = 1;
}
// *** page code end ***
$sql = "SELECT * FROM `med_other` $sql_where  LIMIT $start_limit, $ppp";

$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    if ($action == "search" && trim($search_key) != "") {
        $rs['mkey'] = str_replace($search_key, "<font color=red>$search_key</font>", $rs['mkey']);
		$rs['mvalue'] = str_replace($search_key, "<font color=red>$search_key</font>", $rs['mvalue']);
		 }
    $out_ary[] = $rs;
}

$page_show = getPageStr($sql_all_num, $page, $ppp, $page_url);

$debug = 1;
debuginfo();

include_once('menu_list.php');
require_once PrintEot('a_header');
require_once PrintEot('a_m_other');
require_once PrintEot('a_footer');

?>